package com.myh.cc.coom.singer.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.myh.cc.coom.singer.bean.SingerDetailsBean
import com.myh.cc.databinding.ItemSingerDetailsBinding
import com.myh.cc.widget.OnItemClickListener

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/17.   ：
 */
class SingerDetailsAdapter(bean: SingerDetailsBean) : RecyclerView.Adapter<SingerDetailsAdapter.VH>(){

    val bean = bean

    var mListener: OnItemClickListener? = null

    override fun onBindViewHolder(holder: VH, position: Int) {
        var  list = bean.data.list[position]

        holder.binding.itemDetailsTvMusicName.text = list.musicData.songname
        holder.binding.itemDetailsTvAuthName.text = bean.data.singer_name

        holder.binding.itemRelaSingerDetails.setOnClickListener{
        
            view ->
            mListener?.onClick(view,position)
        }

    }

    override fun getItemCount(): Int {
        return bean.data.list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return SingerDetailsAdapter.VH.create(LayoutInflater.from(parent.context),parent)
    }



    class VH(binding: ItemSingerDetailsBinding): RecyclerView.ViewHolder(binding.root) {

        val binding = binding

        companion object {

            fun create(inflater: LayoutInflater, parent: ViewGroup): SingerDetailsAdapter.VH {

                val binding = ItemSingerDetailsBinding.inflate(inflater, parent, false)
                return SingerDetailsAdapter.VH(binding)
            }


        }
    }
}